package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    /**
     * 根据用户编号与密码查询用户信息
     *
     * @param request
     * @return
     */
    public User getUserByIdByPass(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        UserService userService = new UserServiceImpl();
        User userByIdByPass = userService.getUserByIdByPass(userId, password);
        return userByIdByPass;
    }

    /**
     * 根据用户编号查询用户表返回的行数
     *
     * @param request
     * @return
     */
    public Integer getUserById(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        UserService userService = new UserServiceImpl();
        Integer userById = userService.getUserById(userId);
        return userById;
    }

    /**
     * 向用户表中添加一条记录
     *
     * @param request
     * @return
     */
    public Integer saveUser(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        String userName = request.getParameter("userName");
        String userSex = request.getParameter("userSex");
        UserService userService = new UserServiceImpl();
        Integer integer = userService.saveUser(userId, password, userName, Integer.valueOf(userSex));
        return integer;
    }
}
